#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
    double xishu[1001]={0};
    int k;
    cin>>k;
    while (k--)//读入数组
    {
        int n;
        double d;
        cin>>n>>d;
        xishu[n]+=d;
    }
    cin>>k;
    while (k--)
    {
        int n;
        double d;
        cin>>n>>d;
        xishu[n]+=d;
    }
    int sum=0;
    for(int i=0;i<1001;i++){
        if(xishu[i]!=0)
            sum++;
    }
    cout<<sum;
    for(int i=1000;i>=0;i--){
        if(xishu[i]!=0)
        printf(" %d %.1f",i,xishu[i]);
    }
}